package com.atguigu.spzx.service.handler;

import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.service.exception.GuiguException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){

        e.printStackTrace();
        return Result.build(null,201,e.getMessage());

    }

    @ExceptionHandler(GuiguException.class)
    @ResponseBody
    public Result error(GuiguException e){

        e.printStackTrace();
        return Result.build(null,e.getResultCodeEnum());

    }

}
